using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Routing;
using FubuMVC.Core.Behaviors;
using FubuMVC.Core.Config;
using FubuMVC.Core.Runtime;
using Microsoft.Practices.ServiceLocation;
using NUnit.Framework;
using Rhino.Mocks;

namespace FubuMVC.Tests.Runtime
{
    [TestFixture]
    public class FubuRouteHandlerTester
    {
        private FubuRouteHandler _handler;
        private UrlAction _action;
        private IServiceLocator _locator;
        private IFubuHttpHandler _httpHandler;

        [SetUp]
        public void SetUp()
        {
            _action = new UrlAction();
            _locator = MockRepository.GenerateStub<IServiceLocator>();
            _httpHandler = MockRepository.GenerateStub<IFubuHttpHandler>();
            _handler = new FubuRouteHandler(_action, _locator);
        }

        [Test]
        public void should_return_a_fubuhttphandler_with_the_current_requestcontext()
        {
            _locator.Expect(l => l.GetInstance<IFubuHttpHandler>(_action.UniqueId.ToString())).Return(_httpHandler);

            //NOTE: I'm told that the following 4 lines are the result of making things 'easier to mock'
            var context =
                new RequestContext(
                    new HttpContextWrapper(new HttpContext(new HttpRequest("foo.txt", "http://test", ""), new HttpResponse(Console.Out))),
                    new RouteData());

            var httpHandler = _handler.GetHttpHandler(context);

            httpHandler.ShouldBeOfType<IFubuHttpHandler>().CurrentRequestContext.ShouldBeTheSameAs(context);

        }
    }
}